package io.growing.adaptor.common.async;

import lombok.Getter;

/**
 * @ClassName PriorityRunnable @Description 带有优先级标志的Runnble @Author wangjiu @Date 2021/12/9 10:24 上午
 */
class PriorityRunnable implements Runnable, Comparable<PriorityRunnable> {

    private final Runnable target;

    @Getter private final int priority;

    PriorityRunnable(Runnable target, int priority) {
        this.target = target;
        this.priority = priority;
    }

    @Override
    public void run() {
        target.run();
    }

    @Override
    public int compareTo(PriorityRunnable o) {
        return priority - o.priority;
    }
}
